/*
 * @Author: Wangjun
 * @Date: 2023-08-03 09:51:03
 * @LastEditTime: 2023-09-20 17:49:26
 * @LastEditors: Wangjun
 * @Description:
 * @FilePath: \nodex\nodelogic\op_sw.go
 * hnxr
 */
package nodelogic

import (
	"gitee.com/hnxr_1/nodex"
)

func init() {
	nodex.Reister(new(SW))
}

type SW struct {
	nodex.Node
	Soff nodex.Boolean `remark:"输入1"`
	Son  nodex.Boolean `remark:"输入2"`
	SW   nodex.Boolean `remark:"选择开关"`
	Y    nodex.Boolean `remark:"输出Y,,out"`
}

func (m *SW) GetModelID() int {
	return nodex.ModLogic
}

/**
 * @description:
 * @return {*}
 */
func (m *SW) GetName() string {
	return "SW"
}

func (m *SW) RegData() []byte {
	return nodex.MakeRegData(m, "开关量选择器", m.GetName(), "")
}

func (m *SW) Calc() (err error) {
	if m.EnQ {
		if *m.SW.Bad || *m.Soff.Bad || *m.Son.Bad {
			m.Bad = true
			return //不计算
		}
	}

	if m.SW.Value {
		m.Y.Value = m.Son.Value
	} else {
		m.Y.Value = m.Soff.Value
	}
	m.Bad = false
	return
}
